home *** CD-ROM | disk | FTP | other *** search
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.midlet.MIDlet;
-
- public class Compass extends MIDlet implements CommandListener {
- Display display;
- Command northCmd = new Command("North", 4, 1);
- Command southCmd = new Command("South", 3, 1);
- Command yesCmd = new Command("Yes", 4, 1);
- Command noCmd = new Command("No", 3, 1);
- Command okCmd = new Command("OK", 4, 1);
- Command exitCmd = new Command("Exit", 7, 1);
- boolean northern = true;
- boolean daylightSaving;
-
- public void startApp() {
- this.display = Display.getDisplay(this);
- this.getHemispere();
- }
-
- public void getHemispere() {
- Form form = new Form("");
- form.append("Are you in the North or Southern Hemispere?");
- ((Displayable)form).addCommand(this.northCmd);
- ((Displayable)form).addCommand(this.southCmd);
- ((Displayable)form).setCommandListener(this);
- this.display.setCurrent(form);
- }
-
- public void getDaylightSaving() {
- Form form = new Form("");
- form.append("Are you in daylight savings time?");
- ((Displayable)form).addCommand(this.yesCmd);
- ((Displayable)form).addCommand(this.noCmd);
- ((Displayable)form).setCommandListener(this);
- this.display.setCurrent(form);
- }
-
- public void showInstructions() {
- Form form = new Form("");
- form.append("Now lie the phone flat so that the top of the phone points towards the sun.");
- ((Displayable)form).addCommand(this.okCmd);
- ((Displayable)form).setCommandListener(this);
- this.display.setCurrent(form);
- }
-
- public void showCompas() {
- Canvas canvas = new CompassCanvas(this);
- ((Displayable)canvas).addCommand(this.exitCmd);
- ((Displayable)canvas).setCommandListener(this);
- this.display.setCurrent(canvas);
- }
-
- public void commandAction(Command c, Displayable s) {
- if (c == this.northCmd) {
- this.northern = true;
- this.getDaylightSaving();
- } else if (c == this.southCmd) {
- this.northern = false;
- this.getDaylightSaving();
- } else {
- if (c == this.yesCmd) {
- this.daylightSaving = true;
- this.showInstructions();
- } else if (c == this.noCmd) {
- this.daylightSaving = false;
- this.showInstructions();
- } else if (c == this.okCmd) {
- this.showCompas();
- } else if (c == this.exitCmd) {
- this.destroyApp(false);
- ((MIDlet)this).notifyDestroyed();
- }
-
- }
- }
-
- public void pauseApp() {
- }
-
- public void destroyApp(boolean unconditional) {
- }
- }
-